<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Add message to a hash</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.sodium-crypto-generichash-keygen.html">« sodium_crypto_generichash_keygen</a></li>
      <li style="float: right;"><a href="function.sodium-crypto-generichash.html">sodium_crypto_generichash »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.sodium.html">Sodium 函数</a></li>
    <li>Add message to a hash</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.sodium-crypto-generichash-update" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_generichash_update</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">sodium_crypto_generichash_update</span> &mdash; <span class="dc-title">Add message to a hash</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-generichash-update-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>sodium_crypto_generichash_update</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$state</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Appends a message to the internal hash state.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-generichash-update-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">state</code></dt>

    <dd>

     <p class="para">
      The return value of <span class="function"><a href="function.sodium-crypto-generichash-init.html" class="function">sodium_crypto_generichash_init()</a></span>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">message</code></dt>

    <dd>

     <p class="para">
      Data to append to the hashing state.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-generichash-update-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sodium-crypto-generichash-update-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="sodium-crypto-generichash-update.example.basic">
   <p><strong>示例 #1 <span class="function"><strong>sodium_crypto_generichash_update()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$messages&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #0000BB">random_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">32</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">random_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">32</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">random_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">16</span><span style="color: #007700">)];<br /></span><span style="color: #0000BB">$state&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sodium_crypto_generichash_init</span><span style="color: #007700">();<br />foreach&nbsp;(</span><span style="color: #0000BB">$messages&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sodium_crypto_generichash_update</span><span style="color: #007700">(</span><span style="color: #0000BB">$state</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">$final&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sodium_crypto_generichash_final</span><span style="color: #007700">(</span><span style="color: #0000BB">$state</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">sodium_bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$final</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$allAtOnce&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sodium_crypto_generichash</span><span style="color: #007700">(</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$messages</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">sodium_bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$allAtOnce</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
string(64) &quot;e16e28bbbbcc39d9f5b1cbc33c41f1d217808640103e57a41f24870f79831e04&quot;
string(64) &quot;e16e28bbbbcc39d9f5b1cbc33c41f1d217808640103e57a41f24870f79831e04&quot;
</pre></div>
   </div>
  </div>
 </div>


</div></div></div></body></html>